﻿<template>
    <div style="height:100%;">
        <Row>
            <Col span="24" class="col-margin">
            <!--根据需求删除不不要查询条件-->
            填报年份：
            <Select v-model="searchModel.FillInYear" placeholder="全部" :label-in-value="true" @on-change="initReport()" style="width:200px">
                <Option v-for="item in yearList" :value="item.DictValue" :key="item.DictValue">{{ item.DictText }}</Option>
            </Select>
            <Button icon="ios-search" type="ghost" @click="getPageData()">查询</Button>
            <Button icon="ios-download" type="info" @click="ExcelDown()" style="float:right;margin-right:20px" v-show="isCreated&&ReportStatus >1">数据导出</Button>
            <Upload :on-success="handleSuccess" :action="GetPostUrl()" style="float:right;margin-right:20px" v-show="isCreated&&ReportStatus <3">
                <Button type="success" icon="ios-cloud-upload-outline">数据导入</Button>
            </Upload>
            <Button icon="ios-download" type="warning" @click="TmpDown()" style="float:right;margin-right:20px">模板下载</Button>
            </Col>
        </Row>   
        <div v-show="isCreated">    
        <Row>
            <Col span="24" class="col-margin">
            <div style="text-align:right;font-size:16px;margin-right:50px;">当前状态：
                <label style="font-size:16px">
                    <span v-if="ReportStatus==0" class="Error">退回重报</span>
                    <span v-else-if="ReportStatus==1" class="NoReport">未填写</span>
                    <span v-else-if="ReportStatus==2" class="AlreadyReport">已填写</span>
                    <span v-else-if="ReportStatus==3" class="UpReport">已上报</span>
                    <span v-else-if="ReportStatus==4" class="Success">审核通过</span>
                </label>
                <span style="float:right;" v-show="ReportStatus==0">[<a @click="ReasonShow=true">未通过原因</a>]</span>
            </div>            
            <div id="griddiv" style="overflow-y:auto" v-bind:style="{ height: clientHeight + 'px' }">
                <Form ref="dataModel" :model="Model.dataModel" :rules="ruleValidate" >
                <!-- <Tabs type="card">
                    <TabPane label="销售情况">                                                                                                                                                                                                                                                    
                        <table class="reptable">
                            <thead>
                                <tr>
                                    <th colspan="11">销售情况</th>                                   
                                </tr>
                                <tr>
                                    <th rowspan="3">全年生产总量(万吨）</th>
                                    <th colspan="2">其中外销量（出县）</th>                                                                                                                                                                                                  
                                    <th colspan="4">自留（万吨）</th>                                                                                   
                                    <th rowspan="3">全年生产总产值（万元）</th>
                                    <th colspan="2">其中外销产值（出县）</th>                                                                                                           
                                    <th rowspan="3">销售区域</th>                                                                                       
                                </tr>
                                <tr>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                                    <th rowspan="2">外销量（万吨）</th>
                                    <th rowspan="2">比上年增减%</th>
                                    <th rowspan="2">自留总量</th>
                                    <th colspan="3">其中</th>
                                    <th rowspan="2">外销产值（万元）</th>
                                    <th rowspan="2">比上年增减%</th>                                    
                                </tr>
                                <tr>
                                    <th>鲜食</th>
                                    <th>饲用</th>
                                    <th>种薯</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ProductYield">
                                            <Form-item  prop="ProductYield">
                                                <Input v-model="Model.dataModel.ProductYield" ></Input>
                                            </Form-item>
                                        </Poptip>
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleYield">   
                                            <Form-item  prop="SaleYield">
                                                <Input v-model="Model.dataModel.SaleYield" ></Input>
                                            </Form-item> 
                                        </Poptip>
                                    </td>
                                    <td  v-if="Model.dataModel.SaleYield&&Model.oldDataModel.SaleYield&&Model.oldDataModel.SaleYield*1 !=0">{{Model.dataModel.PecSaleYield=(Model.dataModel.SaleYield*1-Model.oldDataModel.SaleYield*1)/(Model.oldDataModel.SaleYield*1)*100}}</td>                    
                                    <td v-else>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.PecSaleYield">  
                                            <Form-item  prop="PecSaleYield">
                                                <Input v-model="Model.dataModel.PecSaleYield" ></Input>
                                            </Form-item> 
                                        </Poptip>
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ZLyield">  
                                            <Form-item  prop="ZLyield">
                                                <Input v-model="Model.dataModel.ZLyield" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.XSyield"> 
                                            <Form-item  prop="XSyield">
                                                <Input v-model="Model.dataModel.XSyield" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SYyield">  
                                            <Form-item prop="SYyield">
                                                <Input v-model="Model.dataModel.SYyield" ></Input>
                                            </Form-item>
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ZSyield">   
                                            <Form-item  prop="ZSyield">
                                                <Input v-model="Model.dataModel.ZSyield" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ProductOutput">  
                                            <Form-item  prop="ProductOutput">
                                                <Input v-model="Model.dataModel.ProductOutput" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleOutput">  
                                            <Form-item  prop="SaleOutput">
                                                <Input v-model="Model.dataModel.SaleOutput" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td  v-if="Model.dataModel.SaleOutput&&Model.oldDataModel.SaleOutput&&Model.oldDataModel.SaleOutput*1 !=0">{{Model.dataModel.PecSaleOutput=(Model.dataModel.SaleOutput*1-Model.oldDataModel.SaleOutput*1)/(Model.oldDataModel.SaleOutput*1)*100}}</td>                    
                                   
                                    <td v-else>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.PecSaleOutput">  
                                            <Form-item  prop="PecSaleOutput">
                                                <Input v-model="Model.dataModel.PecSaleOutput" ></Input>
                                            </Form-item>  
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleZone"> 
                                            <Form-item  prop="SaleZone">
                                                <Input v-model="Model.dataModel.SaleZone" type="textarea" :autosize="true"></Input>
                                            </Form-item>  
                                        </Poptip> 
                                    </td>                                    
                                </tr>
                            </tbody>
                        </table>
                    </TabPane>
                    <TabPane label="存储情况">
                        <table class="reptable">
                            <thead>
                                <tr>                                    
                                    <th colspan="3">存储情况</th>                                    
                                </tr>
                                <tr>                                    
                                    <th style="height:96px" rowspan="3">存储量（万吨）</th>
                                    <th style="height:96px"  rowspan="3">存储方式</th>
                                    <th style="height:96px"  rowspan="3">库存（万吨）</th>                                                                                        
                                </tr>                                      
                            </thead>
                            <tbody>
                                <tr>                                    
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.StorageNum"> 
                                            <Form-item  prop="StorageNum">
                                                <Input v-model="Model.dataModel.StorageNum" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.StorageWay"> 
                                            <Form-item  prop="StorageWay">
                                                <Input v-model="Model.dataModel.StorageWay" type="textarea" :autosize="true"></Input>
                                            </Form-item> 
                                        </Poptip>  
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.Stock">
                                            <Form-item  prop="Stock">
                                                <Input v-model="Model.dataModel.Stock" ></Input>
                                            </Form-item> 
                                        </Poptip> 
                                    </td>                                    
                                </tr>
                            </tbody>
                        </table>
                    </TabPane>
                    <TabPane label="加工情况">
                        <table class="reptable">
                            <thead>
                                <tr>                                                                       
                                    <th colspan="4">加工情况</th>                                   
                                </tr>
                                <tr style="height:48px" >                                    
                                    <th colspan="2">精淀粉</th>
                                    <th colspan="2">薯片</th> 
                                    <th colspan="2">其他</th>                                                      
                                </tr>
                                <tr style="height:48px" >                                   
                                    <th rowspan="2">加工量（万吨）</th>
                                    <th rowspan="2">产值（万元）</th>
                                    <th rowspan="2">加工量（万吨）</th>
                                    <th rowspan="2">产值（万元）</th>
                                    <th rowspan="2">加工量（万吨）</th>
                                    <th rowspan="2">产值（万元）</th>
                                </tr>                                
                            </thead>
                            <tbody>
                                <tr>                                                                        
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.DFyield"> 
                                            <Form-item  prop="DFyield">
                                                <Input v-model="Model.dataModel.DFyield" ></Input>
                                            </Form-item>  
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.DFoutput">
                                            <Form-item  prop="DFoutput">
                                                <Input v-model="Model.dataModel.DFoutput" ></Input>
                                            </Form-item>   
                                        </Poptip> 
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SPyield">
                                            <Form-item  prop="SPyield">
                                                <Input v-model="Model.dataModel.SPyield" ></Input>
                                            </Form-item> 
                                        </Poptip>  
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SPoutput">
                                            <Form-item  prop="SPoutput">
                                                <Input v-model="Model.dataModel.SPoutput" ></Input>
                                            </Form-item>  
                                        </Poptip> 
                                    </td> 
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.OPyield">
                                            <Form-item  prop="OPyield">
                                                <Input v-model="Model.dataModel.OPyield" ></Input>
                                            </Form-item> 
                                        </Poptip>  
                                    </td>
                                    <td>
                                        <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.OPoutput">
                                            <Form-item  prop="OPoutput">
                                                <Input v-model="Model.dataModel.OPoutput" ></Input>
                                            </Form-item>  
                                        </Poptip> 
                                    </td>                                                                         
                                </tr>
                            </tbody>
                        </table>
                    </TabPane>
                    <TabPane label="备注">
                        <Form-item prop="Remark">
                            <Input v-model="Model.dataModel.Remark" type="textarea" style="width:99%;height:99%"  placeholder="备注长度请小于200个字符..."></Input>
                        </Form-item>
                    </TabPane>
                </Tabs>  -->
                <table class="reptable">
                    <thead>
                        <tr >
                            <th style="background:#ebf7ff" colspan="11">销售情况</th>                                   
                        </tr>
                        <tr>
                            <th rowspan="3">全年生产总量(万吨）</th>
                            <th colspan="2">其中外销量（出县）</th>                                                                                                                                                                                                  
                            <th colspan="4">自留（万吨）</th>                                                                                   
                            <th rowspan="3">全年生产总产值（万元）</th>
                            <th colspan="2">其中外销产值（出县）</th>                                                                                                           
                            <th rowspan="3">销售区域</th>                                                                                       
                        </tr>
                        <tr>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
                            <th rowspan="2">外销量（万吨）</th>
                            <th rowspan="2">比上年增减%</th>
                            <th rowspan="2">自留总量</th>
                            <th colspan="3">其中</th>
                            <th rowspan="2">外销产值（万元）</th>
                            <th rowspan="2">比上年增减%</th>                                    
                        </tr>
                        <tr>
                            <th>鲜食</th>
                            <th>饲用</th>
                            <th>种薯</th>
                        </tr>
                    </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ProductYield">
                                        <Form-item  prop="ProductYield">
                                            <Input v-model="Model.dataModel.ProductYield" ></Input>
                                        </Form-item>
                                    </Poptip>
                                    </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleYield">   
                                        <Form-item  prop="SaleYield">
                                            <Input v-model="Model.dataModel.SaleYield" ></Input>
                                        </Form-item> 
                                    </Poptip>
                                </td>
                                <td  v-if="Model.dataModel.SaleYield&&Model.oldDataModel.SaleYield&&Model.oldDataModel.SaleYield*1 !=0">{{Model.dataModel.PecSaleYield=(Model.dataModel.SaleYield*1-Model.oldDataModel.SaleYield*1)/(Model.oldDataModel.SaleYield*1)*100}}</td>                    
                                <td v-else>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.PecSaleYield">  
                                        <Form-item  prop="PecSaleYield">
                                            <Input v-model="Model.dataModel.PecSaleYield" ></Input>
                                        </Form-item> 
                                    </Poptip>
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ZLyield">  
                                        <Form-item  prop="ZLyield">
                                            <Input v-model="Model.dataModel.ZLyield" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.XSyield"> 
                                        <Form-item  prop="XSyield">
                                            <Input v-model="Model.dataModel.XSyield" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SYyield">  
                                        <Form-item prop="SYyield">
                                            <Input v-model="Model.dataModel.SYyield" ></Input>
                                        </Form-item>
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ZSyield">   
                                        <Form-item  prop="ZSyield">
                                            <Input v-model="Model.dataModel.ZSyield" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.ProductOutput">  
                                        <Form-item  prop="ProductOutput">
                                            <Input v-model="Model.dataModel.ProductOutput" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleOutput">  
                                        <Form-item  prop="SaleOutput">
                                            <Input v-model="Model.dataModel.SaleOutput" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td  v-if="Model.dataModel.SaleOutput&&Model.oldDataModel.SaleOutput&&Model.oldDataModel.SaleOutput*1 !=0">{{Model.dataModel.PecSaleOutput=(Model.dataModel.SaleOutput*1-Model.oldDataModel.SaleOutput*1)/(Model.oldDataModel.SaleOutput*1)*100}}</td>                    
                                   
                                <td v-else>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.PecSaleOutput">  
                                        <Form-item  prop="PecSaleOutput">
                                            <Input v-model="Model.dataModel.PecSaleOutput" ></Input>
                                        </Form-item>  
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SaleZone"> 
                                        <Form-item  prop="SaleZone">
                                            <Input v-model="Model.dataModel.SaleZone" type="textarea" :autosize="true"></Input>
                                        </Form-item>  
                                    </Poptip> 
                                </td>                                    
                            </tr>
                        </tbody>
                    </table>
                    <table class="reptable" style="margin-top:50px;">
                        <thead>
                            <tr>                                    
                                <th style="background:#ebf7ff" colspan="3">存储情况</th> 
                                <th style="background:#ebf7ff" colspan="6">加工情况</th> 
                                <th style="background:#ebf7ff" rowspan="3">备注</th>                                  
                            </tr>
                            <tr>                                    
                                <th rowspan="2">存储量（万吨）</th>
                                <th rowspan="2">存储方式</th>
                                <th rowspan="2">库存（万吨）</th> 
                                <th colspan="2">精淀粉</th>
                                <th colspan="2">薯片</th> 
                                <th colspan="2">其他</th>                                                                                       
                            </tr>
                            <tr>                                   
                                <th>加工量（万吨）</th>
                                <th>产值（万元）</th>
                                <th>加工量（万吨）</th>
                                <th>产值（万元）</th>
                                <th>加工量（万吨）</th>
                                <th>产值（万元）</th>
                            </tr>                                        
                        </thead>
                        <tbody>
                            <tr>                                    
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.StorageNum"> 
                                        <Form-item  prop="StorageNum">
                                            <Input v-model="Model.dataModel.StorageNum" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.StorageWay"> 
                                        <Form-item  prop="StorageWay">
                                            <Input v-model="Model.dataModel.StorageWay" type="textarea" :autosize="true"></Input>
                                        </Form-item> 
                                    </Poptip>  
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.Stock">
                                        <Form-item  prop="Stock">
                                            <Input v-model="Model.dataModel.Stock" ></Input>
                                        </Form-item> 
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.DFyield"> 
                                        <Form-item  prop="DFyield">
                                            <Input v-model="Model.dataModel.DFyield" ></Input>
                                        </Form-item>  
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.DFoutput">
                                        <Form-item  prop="DFoutput">
                                            <Input v-model="Model.dataModel.DFoutput" ></Input>
                                        </Form-item>   
                                    </Poptip> 
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SPyield">
                                        <Form-item  prop="SPyield">
                                            <Input v-model="Model.dataModel.SPyield" ></Input>
                                        </Form-item> 
                                    </Poptip>  
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.SPoutput">
                                        <Form-item  prop="SPoutput">
                                            <Input v-model="Model.dataModel.SPoutput" ></Input>
                                        </Form-item>  
                                    </Poptip> 
                                </td> 
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.OPyield">
                                        <Form-item  prop="OPyield">
                                            <Input v-model="Model.dataModel.OPyield" ></Input>
                                        </Form-item> 
                                    </Poptip>  
                                </td>
                                <td>
                                    <Poptip trigger="hover" title="上年数据" :content="Model.oldDataModel.OPoutput">
                                        <Form-item  prop="OPoutput">
                                            <Input v-model="Model.dataModel.OPoutput" ></Input>
                                        </Form-item>  
                                    </Poptip> 
                                </td> 
                                <td>
                                    <Form-item prop="Remark">
                                        <Input v-model="Model.dataModel.Remark" type="textarea" :autosize="true"  ></Input>
                                    </Form-item>
                                </td>                                    
                            </tr>
                        </tbody>
                    </table>
                </Form>
                <div class="divButton">
                    <Button type="primary" @click="save('dataModel')" :disabled="ReportStatus < 3 ? false:true ">保存</Button>
                    <Button type="primary" @click="DataUp()" :disabled="ReportStatus == 2 ? false:true">上报</Button>
                </div>
                <Alert  type="error">
                    填报时间：每年1月10日
                    <p> 填报说明：1.全省范围内从乡（镇）起，逐级全面统计，由县级填报经州（市）审核后上报。</p> 
                    <span slot="desc"></span>
                </Alert>
            </div>
            </Col>
        </Row>
        </div>
        <div v-show="!isCreated" class="NoCreatedDiv">
            <h1>{{ReportLine}}</h1>
        </div>
        <Modal v-model="ReasonShow" :mask-closable="false" width="500"> 
            <p slot="header" class="title">
                <Icon type="ios-paper" size="20"></Icon>
                <span style="font-size: 20px">未通过原因</span>
            </p>
            <p slot="close">
                <Icon type="close-circled" color="red" size=25></Icon>
            </p>
            <div class="reasonDiv"><Input v-model="Opinion" type="textarea" readonly :autofocus="true" :rows="10"  ></Input></div>
            <p slot="footer"></p>
        </Modal>         
    </div>
</template>
<script>
import axios from 'axios'
export default {
  data() {
    const validateData = (rule, value, callback) => {
      var temp = /^[0-9]\d*(\.\d+)?$/;
      if (value||value==0) {
        if (temp.test(value) == false) {
          callback(new Error("必须是数字！"));
        } else {
          callback();
        }
      } else {
        callback(new Error("不能为空！"));
      }
    };
    return {
        isCreated:false,//是否需要显示报表
        ReportLine:'',//不显示报表时所显示文字
        ReasonShow:false,
        showType: false, //编辑框弹出状态
        yearList: this.GetGroupDict("ReportYear"),
        ReportId: "",
        ReportStatus: "",
        Opinion:'',
        AreaCode: this.GetlocaStorage("potUserinfo").AreaCode,
        smodel:'',
        amodel:'',
        wmodel:'',
        ymodel:'',
        ruleValidate: {
            ProductYield: { validator: validateData, trigger: "blur" },
            SaleYield: { validator: validateData, trigger: "blur" },
            //pecSaleYield:[{ required: true, message: '比上年增减%（产量）不能为空', trigger: 'blur' }],
            ZLyield: { validator: validateData, trigger: "blur" },
            XSyield: { validator: validateData, trigger: "blur" },
            SYyield: { validator: validateData, trigger: "blur" },
            ZSyield: { validator: validateData, trigger: "blur" },
            ProductOutput: { validator: validateData, trigger: "blur" },
            SaleOutput: { validator: validateData, trigger: "blur" },
            //pecSaleOutput:[{ required: true, message: '比上年增减%（产值）不能为空', trigger: 'blur' }],
            //SaleZone:[{ required: true, message: '销售区域不能为空', trigger: 'blur' }],
            StorageNum: { validator: validateData, trigger: "blur" },
            //StorageWay:[{ required: true, message: '存储方式不能为空', trigger: 'blur' }],
            Stock: { validator: validateData, trigger: "blur" },
            DFyield: { validator: validateData, trigger: "blur" },
            DFoutput: { validator: validateData, trigger: "blur" },
            SPyield: { validator: validateData, trigger: "blur" },
            SPoutput: { validator: validateData, trigger: "blur" },
            OPyield: { validator: validateData, trigger: "blur" },
            OPoutput: { validator: validateData, trigger: "blur" },
            // Remark: [
            //     { required: false, message: '备注长度请小于100个字符', trigger: 'blur' },
            //     { type: 'string', max: 100, message: '备注长度请小于200个字符', trigger: 'blur' }
            // ],
        },
        Model: {
            dataModel: {
            Id: "",
            ReportId: "",
            ProductYield: "",
            SaleYield: "",
            PecSaleYield: "",
            ZLyield: "",
            XSyield: "",
            SYyield: "",
            ZSyield: "",
            ProductOutput: "",
            SaleOutput: "",
            PecSaleOutput: "",
            SaleZone: "",
            StorageNum: "",
            StorageWay: "",
            Stock: "",
            DFyield: "",
            DFoutput: "",
            SPyield: "",
            SPoutput: "",
            OPyield: "",
            OPoutput: "",
            Remark: ""
            },
            oldDataModel: {
            Id: "",
            ReportId: "",
            ProductYield: "",
            SaleYield: "",
            PecSaleYield: "",
            ZLyield: "",
            XSyield: "",
            SYyield: "",
            ZSyield: "",
            ProductOutput: "",
            SaleOutput: "",
            PecSaleOutput: "",
            SaleZone: "",
            StorageNum: "",
            StorageWay: "",
            Stock: "",
            DFyield: "",
            DFoutput: "",
            SPyield: "",
            SPoutput: "",
            OPyield: "",
            OPoutput: "",
            Remark: ""
            }
        },

        clientHeight: window.innerHeight - 213, //表格默认高度
        //查询模型：根据需求删除不不要查询条件
        searchModel: {
            ReportCode: "PotSaleStorege",
            FillInYear: new Date().getFullYear() + "",
            PageNumber: 1,
            PageSize: 20
        }
    };
  },
  mounted() {
    //table高度计算方法
    const that = this;
    window.onresize = () => {
      return (() => {
        that.clientHeight = window.innerHeight - 213;
      })();
    };
  },
  methods: {
    getPageData() {
        var self = this;
        self.$http.get("PotSaleStorege", {params: {AreaCode: this.AreaCode,FillInYear: this.searchModel.FillInYear}}).then(function(res) {
            if (res.data.status === 1) {
                self.Model.dataModel = res.data.model.DataModel;
                if (res.data.model.OldDataModel)
                    self.Model.oldDataModel = res.data.model.OldDataModel;
                    self.ReportStatus = res.data.model.ReportStatus;
                    self.ReportId = res.data.model.ReportId;
                    self.Opinion = res.data.model.Opinion;
                    self.isCreated = true;
            }else{
                self.isCreated = false;
                self.ReportLine = '报表未生成！'
                self.ReportStatus = null;
                self.$Modal.error({ title: "提示信息", content: res.data.message });
            }
        });
    },
    //保存方法
    save(modelname) {
      var self = this;
      this.$refs[modelname].validate(valid => {
        if (valid) {
          this.$http.put("PotSaleStorege", this.Model.dataModel).then(function(res) {
              if (res.data.status == 1) {
                    self.getPageData();
                    self.$Notice.success({ title: "保存成功！", desc: false });
              } else {
                self.$Modal.warning({
                  title: "提示信息",
                  content: res.data.message
                });
              }
            });
        }
        else{
            self.$Modal.error({ title: "提示信息", content: '无法保存，请检查是否有未填项！' });
        }
      });
    },
    //数据上报
    DataUp() {
      var self = this;
      
      this.checkData();
    },
    PostUp(){
        var self = this;
        let model = new Object();
        model.Id = this.ReportId;
        model.Status = 3;
        model.Opinion = "";
        self.$Modal.confirm({
          title: "提示信息",
          content: "<p>数据上报后，不能再更改，是否继续上报？</p>",
          onOk: () => {
            this.$http.post("Report/PostUpStatus", model).then(function(res) {
              if (res.data.status == 1) {
                self.showType = false;
                self.$Notice.success({ title: "数据上报成功！", desc: false });
                self.getPageData();
              } else {
                self.$Modal.error({
                  title: "提示信息",
                  content: "数据上报失败!"
                });
              }
            });
          }
        });
    },
    checkData() {
      var self = this;
      //let yArea = 0;//全年合计面积
    //   this.getSeasonData(
    //     this.AreaCode,
    //     this.searchModel.FillInYear,
    //     "1"
    //   ); //大春
    //   this.getSeasonData(
    //     this.AreaCode,
    //     this.searchModel.FillInYear,
    //     "2"
    //   ); //秋作
    //   this.getSeasonData(
    //     this.AreaCode,
    //     this.searchModel.FillInYear,
    //     "3"
    //   ); //冬作
      axios.all([
          self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '1'}}),
          self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '2'}}),
          self.$http.get('PotSeasonProduct',{params:{AreaCode: self.AreaCode,FillInYear: self.searchModel.FillInYear,TimesCycle: '3'}}),
          ]).then(axios.spread(function (res1,res2,res3){
                let smodel = self.listToModel(res1.data.model);
                let amodel = self.listToModel(res2.data.model);
                let wmodel = self.listToModel(res3.data.model);
              //self.confirmData(smodel,amodel,wmodel);
                let yYield = 0; //全年合计产量
                let yOutput = 0; //全年合计产值
                if (smodel != null) {
                    //yArea += smodel.Area*1;
                    yYield += smodel.Yield * 1;
                    yOutput += smodel.Output * 1;
                }
                if (amodel != null) {
                    //yArea += amodel.Area*1;
                    yYield += amodel.Yield * 1;
                    yOutput += amodel.Output * 1;
                }
                if (wmodel != null) {
                    //yArea += wmodel.Area*1;
                    yYield += wmodel.Yield * 1;
                    yOutput += wmodel.Output * 1;
                }
                let t1 = self.Model.dataModel.ProductYield - yYield;
                let t2 = self.Model.dataModel.ProductOutput - yOutput;
                if (t1.toFixed(0)!=0) {
                    self.$Modal.error({
                    title: "提示信息",
                    content:
                        "填报冲突，表五的全年合计总产量不等于表二的各季度产量之和! 无法上报！"
                    });
                // return false;
                }
                else if (t2.toFixed(0) !=0) {
                    self.$Modal.error({
                    title: "提示信息",
                    content:
                        "填报冲突，表五的全年合计总产值不等于表二的各季度产值之和! 无法上报！"
                    });
                // return false;
                }
                else{
                    // return true;
                    self.PostUp();
                }
                
                }))
    },
    listToModel(list){
        let model = new Object();
        model.Area = 0;
        model.Yield = 0;
        model.Output = 0;
        if (list.length > 0) {
              for (var i = 0; i < list.length; i++) {
                var tItem = list[i];
                model.Area += tItem.TotalArea;
                model.Yield += tItem.TotalYield;
                model.Output += tItem.TotalOutput;
              }
              model.Area = model.Area.toFixed(4);
              model.Yield = model.Yield.toFixed(4);
              model.Output = model.Output.toFixed(4);
        }
        return model;
    },
    confirmData(smodel,amodel,wmodel){
    //   var smodel = this.smodel;
    //   var amodel = this.amodel;
    //   var wmodel = this.wmodel;
      let yYield = 0; //全年合计产量
      let yOutput = 0; //全年合计产值
      if (smodel != null) {
        //yArea += smodel.Area*1;
        yYield += smodel.Yield * 1;
        yOutput += smodel.Output * 1;
      }
      if (amodel != null) {
        //yArea += amodel.Area*1;
        yYield += amodel.Yield * 1;
        yOutput += amodel.Output * 1;
      }
      if (wmodel != null) {
        //yArea += wmodel.Area*1;
        yYield += wmodel.Yield * 1;
        yOutput += wmodel.Output * 1;
      }
      console.log("993")
      console.log(smodel)
      let t1 = this.Model.dataModel.ProductYield - yYield;
      let t2 = this.Model.dataModel.ProductOutput - yOutput;
      if (t1.toFixed(0)!=0) {
        this.$Modal.error({
          title: "提示信息",
          content:
            "填报冲突，表五的全年合计总产量不等于表二的各季度产量之和! 无法上报！"
        });
        return false;
      }
      if (t2.toFixed(0) !=0) {
        this.$Modal.error({
          title: "提示信息",
          content:
            "填报冲突，表五的全年合计总产值不等于表二的各季度产值之和! 无法上报！"
        });
        return false;
      }
      return true;
    },
    getSeasonData(AreaCode, FillInYear, TimesCycle) {
      var self = this;
      let model = new Object();
      model.Area = 0;
      model.Yield = 0;
      model.Output = 0;
      this.$http
        .get("PotSeasonProduct", {
          params: {
            AreaCode: AreaCode,
            FillInYear: FillInYear,
            TimesCycle: TimesCycle
          }
        })
        .then(function(res) {
          if (res.data.status == 1) {
            self.seasondataList = res.data.model;
            if (self.seasondataList.length > 0) {
              for (var i = 0; i < self.seasondataList.length; i++) {
                var tItem = self.seasondataList[i];
                model.Area += tItem.TotalArea;
                model.Yield += tItem.TotalYield;
                model.Output += tItem.TotalOutput;
              }
              model.Area = model.Area.toFixed(2);
              model.Yield = model.Yield.toFixed(2);
              model.Output = model.Output.toFixed(2);
              if(TimesCycle=='1'){
                  self.smodel = model;
              }
              else if(TimesCycle == '2'){
                  self.amodel = model;
              }
              else{
                  self.wmodel = model;
              }
            }
          }
        });
    },
    //模板下载
    TmpDown: function() {
      window.open(
        this.$http.defaults.baseURL +
          "Report/GetTemplateData?ReportCode=" +
          this.searchModel.ReportCode
      );
    },
    //导入
    GetPostUrl() {
      var url =
        this.$http.defaults.baseURL +
        "PotSaleStorege/PostImportData?ReportId=" +
        this.ReportId;
      return url;
    },
    //导入成功反馈事件
    handleSuccess(res, file) {
      var self = this;
      self.getPageData();
      if (res.status == -1) {
        self.$Modal.warning({
          title: "提示信息",
          content: res.message
        });
      } else {
        self.$Notice.success({
          title: "数据导入成功！",
          desc: false
        });
      }
    },
    //导出
    ExcelDown: function() {
      window.open(
        this.$http.defaults.baseURL +"PotSaleStorege/GetExcelData?FillInYear=" +this.searchModel.FillInYear +"&&AreaCode=" +this.AreaCode);
    },
    initReport(){
        var today = new Date();
        let currentYear = today.getFullYear();
        let currentMonth = today.getMonth() + 1;
        if(this.searchModel.FillInYear*1 == currentYear &&currentMonth==12){
            this.getPageData();
        }
        else if(this.searchModel.FillInYear*1 == currentYear-1 && currentMonth >= 1 && currentMonth <= 5){
            this.getPageData();
        }
        else if(this.searchModel.FillInYear < currentYear){
            this.getPageData();
        }
        else {
            this.isCreated = false;
            this.ReportLine = '不在填报时间内！';
        }
    }

  },
  //创建Vue页面方法
  created: function() {
    //创业Vue前调用获取this.datas: {},//table数据对象
    this.initReport();
  },
  watch: {
    //需要监听的在此处新增监听对象
  }
};
</script>
